/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.prototype.console;

import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author zineddine
 */
public class JobGenerateStat {
    /**.
     * @param pathStatSvn path of the jar of statsvn
     */
    private String pathStatSvn;
    /**.
     * @param pathSvn path which contains downloaded projects
     */
    private String pathSvn;
    /**.
     * @param commandeSvn command to download a project from SF
     */
    private String commandeSvn;

    /**.
     * Constructor
     * @param cheminSVN
     * @param cheminStatSVN
     * @param commandeSVN
     */
    public JobGenerateStat(final String cheminStatSVN, final String cheminSVN,
            final String commandeSVN) {
        this.pathStatSvn = cheminSVN;
        this.pathSvn = cheminStatSVN;
        this.commandeSvn = commandeSVN;
    }

    /**.
     * Generate analysis results
     * @throws IOException
     */
    public  void call() throws IOException  {
        try {
             String folderProject;
             folderProject = commandeSvn
                     .substring(commandeSvn.lastIndexOf(" ") + 1);
             File folderSVN = new File(pathSvn + folderProject);
             String folderProjectStat = folderProject + "Stat";
             File emplacementSVN = new File(pathSvn);

             File folderStat = new File(pathSvn + folderProjectStat);
             Process rt =  Runtime.getRuntime()
                 .exec("cmd.exe /c MD " + folderProjectStat,
                 null, emplacementSVN);
             rt.waitFor();
             Process rt2 = Runtime.getRuntime()
                 .exec("cmd.exe /c svn log --xml -v > svn.log",
                 null, folderSVN);
             rt2.waitFor();

             Runtime.getRuntime()
                   .exec("java -jar "  + pathStatSvn + " " + pathSvn
                     + folderProject + "\\svn.log" + " " + pathSvn
                     + folderProject, null, folderStat);

            } catch (InterruptedException ex) {
                Logger.getLogger(JobGenerateStat.class.getName())
                            .log(Level.SEVERE, null, ex);
            }
    }
}